<template>
  <section>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>帐户余额</span>
      </div>
      <div class="text item">
        <div class="unit">￥{{ accountInfo.amount }}</div>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-top: 15px">
      <div slot="header" class="clearfix">
        <span>消费明细</span>
      </div>
      <div class="text item">
        <el-table :data="data" highlight-current-row="">
          <el-table-column type="index" label="序号" min-width="55"/>
          <el-table-column prop="remark" label="课消说明"/>
          <el-table-column prop="amount" label="课消金额（元）"/>
          <el-table-column prop="createdAt" label="结算时间">
            <template slot-scope="scope">
              {{ scope.row.createdAt | formatDate('yyyy-MM-dd hh:mm') }}
            </template>
          </el-table-column>
        </el-table>

        <!--分页工具条-->
        <el-col :span="24" class="toolbar">
          <!--分页组件-->
          <el-pagination
            :total="total"
            style="margin: 8px 0 8px;"
            layout="total, prev, pager, next, sizes"
            @size-change="sizeChange"
            @current-change="pageChange"/>
        </el-col>
      </div>
    </el-card>
  </section>
</template>

<script>
import initData from '@/mixins/initData'
import { getStudentAccount } from "@/api/student"

export default {
  mixins: [initData],
  props: {
    studentId: {
      type: [String, Number],
      required: true
    }
  },
  data() {
    return {
      accountInfo: {
        amount: 0
      }
    }
  },
  methods: {
    beforeInit() {
      this.url = 'student/consumeList'
      const sort = 'id,asc'
      this.params = {
        studentId: this.studentId,
        type: 2,
        page: this.page,
        size: this.size,
        sort: sort
      }
      return true
    },
    handleCurrentChange(val) {
      this.page = val
      this.getStudentConsumeList()
    },
    getStudentAccount() {
      let para = {
        studentId: this.studentId
      };
      getStudentAccount(para).then(res => {
        this.accountInfo = res.data
      })
    }
  },
  created() {

  },
  mounted() {
    this.$nextTick(() => {
      this.init()
    })
    this.getStudentAccount()
  }
}
</script>

<style>
  .unit {
    display: inline-block;
    width: 100%;
    height: 28px;
    line-height: 30px;
    font-size: 26px;
    color: #333;
  }
</style>
